FinalMess:
 ld   hl,$ff40
 res  3,[hl]
 call initFullScreen
 rst  40
 db   %01110010    ; b,hl,a
 db   16
 dw   snowPal
 db   0
 db   $58          ; SetBkgPalette

 rst  40
 db   %01110010
 db   16
 dw   snowPal
 db   0
 db   $5a          ;

 ld   hl,FinalWords
 call PrintMessPass
 rst  8
 ld   hl,$8000+104*16+1
 ld   [hl],$80
 ld   a,%10010011      
 ldio [$40],a 
 call InitSnow
mainSnow:                   
 halt
 ld   hl,VblankFlag
 inc  [hl]
 dec  [hl]
 jr   z,mainSnow
 dec  [hl]
 call MovingSnow
 jr   mainSnow          ; Do it all over again!
;
MovingSnow:
 ld   hl,SpeedArray
MovingSnowLoop:
 ld   a,[hli]
 or   a
 ret  z
 dec  [hl]
 jr   nz,MovingSnowLoop1 
 ld   [hl],a
 ld   a,l
 rra

 call GetObjectInfo
 push de
 push hl
 ld   l,c
 ld   h,$c2
 dec  l
 ld   a,b
 cp   [hl]
 inc  l
 inc  l
 jr   nc,MovingRight    ; Nalevo nelxzja!
 cp   [hl]
 jr   nc,MovingLeft     ; Mojno tolxko nalewo
 call getRnd
 and  1
 jr   nz,MovingLeft     ;
MovingWprawo:
 ld   a,c
 cp   168
 jr   z,Inc_b
 inc  c                 ; Wprawo
 jr   Inc_b

MovingRight:
 cp   [hl]
 jr   c,MovingWprawo    ; Wprawo mojno
 dec  l                 ; Jamka
 cp   [hl]
 jr   nz,Inc_b
 dec  [hl]              ; Set pixel on bground
 call GetAdress
 ld   a,b
 and  7
 jr   z,SetPix3
 inc  l              
 inc  hl 
 dec  a
 jr   nz,@-3
SetPix3:
 ld   a,c
 and  7
 ld   b,a
 ld   a,128
 jr   z,SetPix4
 rrca  
 dec  b
 jr   nz,@-2
SetPix4:
 ld   b,a
 inc  l
 rst  56
 ld   a,[hl]
 or   b
 ld   b,a
 rst  56
 ld   [hl],b

 pop  hl
 pop  de
 ld   a,l
 rra
 push hl
 call InitOneSnow
 pop  hl
 jr   MovingSnowLoop1

MovingLeft:
 ld   a,c
 cp   8
 jr   z,Inc_b
 dec  c
Inc_b:
 inc  b
 
MoveNext:
 pop  hl
 pop  de
 ld   a,l
 rra  
 call SetObjectFull

MovingSnowLoop1:
 inc  hl
 jr   MovingSnowLoop
 
PrintMessActive:
 db   62            ; code of 'ld a,n'
PrintMessPass:
 xor  a
 ld   [PrintMode],a
PrintMess:
 ld   a,[hli]
 cp   $ff
 ret  z
 cp   32
 jr   nc,PrintSymbol
 ld   de,PrintMess
 push de
 cp   13
 jr   nz,no_enter
 push hl
 ld   hl,PrintXY+1
 ld   a,8
 add  a,[hl]
 ld   [hld],a
 ld   a,[PrintX]
 ld   [hl],a
 ld   hl,PrintTiles
 ld   a,[hli]
 ld   d,[hl]
 add  a,$10
 jr   nc,@+3
 inc  d
 ld   [hl],d   ; new higbyte of tile adress
 dec  hl
 ld   [hl],a   ; new lowbyte 
 pop  hl
 ret
no_enter:
 cp   22
 jr   nz,no_at
 ld   a,[hl]            ; new X
 ld   [PrintX],a
 rst  40
 db   %00001101         ; c,de
 db   2                 ; len
 dw   PrintXY           ; dest
 db   $52               ; CopyHLtoDEinC
 ret
no_at:
 cp   16
 jr   nz,no_attr
 ld   a,[hli]
 ld   [PrintAtr],a
 ret
no_attr:
 cp   17
 jr   nz,no_tileadr
 ld   a,[hli]
 ldio [$4f],a
 rst  40
 db   %00001101         ; c,de
 db   2                 ; len
 dw   PrintTiles        ; dest
 db   $52               ; CopyHLtoDEinC
 ret

no_tileadr:
 cp   19
 jr   nz,noPals
 ld   a,[hli]          ; index of Pal
 ld   b,[hl]           ; how many Pals *4
 inc  hl
 jp   SetBkgPalette
noPals:
PrintSymbol:
 push hl
 push af
 call GetTileAdress
 pop  af
 sub  32
 jr   z,PrintGot
 sub  14
 cp   13
 jr   c,PrintGot
 sub  5
PrintGot:
 ld   d,MyFnt/256       ; Here my packed fontSet/2 letters in 7 bytes
 srl  a
 rl   c
 ld   e,a
 add  a,a               ;
 add  a,a               ; *7
 add  a,a               ;
 sub  e                 ;
 ld   e,a
 ld   b,7
PrintLoop1:
 push bc
 ld   a,[de]
 inc  de
 bit  0,c
 jr   nz,@+4
 swap a
 and  $f
 bit  3,c
 jr   nz,@+4
 swap a
 ld   b,a
 waitvblank
 ld   a,b
 or   [hl]
 ld   [hli],a
 inc  l
 pop  bc
 dec  b
 jr   nz,PrintLoop1
 ld   hl,PrintXY
 ld   a,[hli]
 ld   c,a          ; xpos
 ld   b,[hl]       ; ypos
 dec  hl
 add  a,4
 cp   $a8          ;!!! remake this verifying to edge
 jr   nz,@+9
 inc  hl
 ld   a,b
 add  a,8
 ld   [hld],a
 ld   a,8          ; x0   !!!
 ld   [hl],a       ; also !!!
 ld   a,[PrintMode]
 or   a
 jr   z,noActive
 ld   hl,PrintTiles
 ld   a,[hli]
 ld   d,[hl]
 ld   e,a
 push de
 bit  2,c
 jr   z,noNextTile
 add  a,$10
 jr   nc,@+3
 inc  d
 ld   [hl],d   ; new higbyte of tile adress
 dec  hl
 ld   [hl],a   ; new lowbyte 
noNextTile:
 pop  de
 ldio a,[$4f]  ; VBK (VRAM Bank) char code 
 push af
 rla           ;
 rla           ; bank specification is 3rd bit
 rla           ;
 and  8        ; 
 ld   hl,PrintAtr
 or   [hl]     
 ld   h,a      ; code for attr map
 ld   a,d
 and  $f
 ld   d,a
 ld   a,e
 and  %11110000
 or   d
 swap a
 ld   l,a      ; code for char map
 push hl
 call getBgAdrFromPix  ; bc=>hl adress on bg map
 pop  de       ; e:char code; d:attr code
 rst  0
 rst  56
 ld   [hl],e
 rst  8
 rst  56
 ld   [hl],d
 pop  af
 ldio [$4f],a
noActive:
 pop  hl
 jp   PrintMess
;
GetTileAdress:
 ld   a,[PrintMode]
 or   a
 ld   hl,PrintXY
 ld   c,[hl]
 jr   nz,PrintActiveGetTile
 inc  hl
 ld   b,[hl]
 jp   GetAdress     ; beside later!!!
PrintActiveGetTile:
 ld   hl,PrintTiles
 ld   a,[hli]
 ld   h,[hl]
 ld   l,a
 ret
;
InitSnow:
 ld   a,40
InitSnowLoop:
 dec  a
 push af
 call InitOneSnow
 pop  af
 jr   nz,InitSnowLoop
 ld   [SpeedArray+80],a
 ld   hl,HorizArray
 ld   [hl],yMax
 inc  l
 jr   nz,@-3
 ld   l,7     
 ld   [hl],0
 ld   l,168
 ld   [hl],0 

 ld   a,40
isl2:
 dec  a
 push af
 ld   a,100              ; at first, all snow is on full screen /0..99 y
 call getRand
 ld   c,a
 pop  af
 push af
 call SetObjectY
 pop  af
 jr   nz,isl2
 ret

InitOneSnow:            ; a - nomer snow
 ld   e,a
 ld   a,160      ;20
 call getRand
 add  a,8     ;78
 ld   c,a               ; x cord
 call getRnd
 and  15
 add  a,16
 ld   b,a               ; y cord
 call getRnd
 and  1
 inc  a                 ; speed
 ld   d,0
 ld   hl,SpeedArray
 add  hl,de
 add  hl,de
 ld   [hli],a
 ld   [hl],a
 ld   a,e
 ld   de,$868
 jp   SetObjectFull
